<template>
  <div class="classify">
    <!-- 搜索框 -->
    <div class="search">
      <van-cell-group inset>
        <van-field
          center
          left-icon="search"
          right-icon="photograph"
          clearable
          placeholder="商品/大家都在看/大家都在买"
        >
          <template #button>
            <van-button size="small" style="{color: #000;}">搜索</van-button>
          </template>
        </van-field>
      </van-cell-group>
    </div>
    <div class="main">
      <!-- 左侧导航 -->
      <van-tree-select
        v-model:main-active-index="activeIndex"
        height="149vw"
        :items="shoeList"
      >
        <!-- 右侧内容 -->
        <template #content >

          <div v-for="(goods,index) in shoeList" :key="goods.id">
            
            <div class="recommend" v-if="activeIndex === index">
              <div class="rec-item" v-for="good in goods.children">
                <!-- 二级名称 -->
                <h1>{{good.name}}</h1>
                <ul class="googs">
                  <li class="good" v-for="item in good.s_goods" @click="shopInfo(item)">
                    <img :src="item.s_goods_photos[0].path" alt="">
                    <van-text-ellipsis :content="item.name" />
                  </li>
                </ul>
              </div>
            </div>
          </div>

        </template>
      </van-tree-select>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import goodsStore from '@/stores/good'
const goodStore=goodsStore()
const router=useRouter()
// 导航索引
const activeIndex = ref(0);
// 所有分类  左侧导航名数组
const shoeList=ref([])
// 获取所有商品分类
goodStore.getGoods({project_id:1,limit:1000})
const goodList=JSON.parse(localStorage.getItem('goodList'))
goodList.forEach(ele => {
  shoeList.value.push({
    text:ele.name,
    id:ele.id,
    children:ele.children
  })
})
// 路由跳转
const shopInfo=(item)=>{
  localStorage.setItem('good',JSON.stringify(item))
  router.push('/ProductInfo')
}
</script>

<style lang='scss' scoped>
.classify{
  padding-top: 2.6667vw;
  width: 100vw;
  box-sizing: border-box;
  .search{
    height: 13.3333vw;
    border-bottom: 1px solid #f4f4f8;
    .van-cell-group{
      .van-cell{
        background-color: #f4f4f8;
        padding: 1vw 1vw 1vw 2vw;
        .van-button{
          background-color: #f4f4f8;
          border: none;
        }
      }
    }
  }

}
.main{
  height: 90vh;
  .recommend{
    .rec-item{
      margin-top: 2.6667vw;
      width: 100%;
      height: 32vw;
      h1{
        font-weight: bold;
        height: 5.3333vw;
        line-height: 5.3333vw;
      }
      .googs{
        display: flex;
        flex-wrap:wrap;
        width: 100%;
        height: 26.6667vw;
        .good{
          margin-left: .7vw;
          width: 21.3333vw;
          height: 26.6667vw;
          background-color: #f4f4f8;
          img{
            width: 100%;
            height: 21.3333vw;
            border-radius: 3vw;
          }
          .van-text-ellipsis{
            height: 5.3333vw;
            line-height: 5.3333vw;
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>
